package cn.shenlong.domain;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.builder.HashCodeBuilder;

/**
 * 树型结点
 * 
 * @author czllfy
 */
public class TreeNode<T> implements Serializable {

	private static final long serialVersionUID = -6431533745432745856L;

	private T id; // ID字段
	private T pId; // 父ID字段
	private String name; // 显示的名称
	private boolean open = false; // 是否打开
	private String target = ""; // 打开的地址
	private Map<String, Object> attributes = new HashMap<String, Object>(); // 附加属性

	public T getId() {
		return id;
	}

	public void setId(T id) {
		this.id = id;
	}

	public T getpId() {
		return pId;
	}

	public void setpId(T pId) {
		this.pId = pId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public boolean isOpen() {
		return open;
	}

	public void setOpen(boolean open) {
		this.open = open;
	}

	public String getTarget() {
		return target;
	}

	public void setTarget(String target) {
		this.target = target;
	}

	public void addAttributes(String key, Object value) {
		this.attributes.put(key, value);
	}

	public Object getAttributes(String key) {
		return this.attributes.get(key);
	}

	public Object getAttributes() {
		return this.attributes;
	}

	public int hashCode() {
		HashCodeBuilder builder = new HashCodeBuilder();
		builder.append(getId());
		builder.append(getpId());
		return builder.toHashCode();
	}

	@SuppressWarnings("rawtypes")
	public boolean equals(Object obj) {
		TreeNode tn = (TreeNode) obj;
		if (tn.hashCode() == hashCode()) {
			return true;
		} else {
			return false;
		}
	}

	public String toString() {
		StringBuffer content = new StringBuffer();
		content.append(getId());
		content.append(",").append(getpId());
		content.append(",").append(getName());
		return content.toString();
	}
}
